package com.example.algorithm.greedy;

import java.util.LinkedList;

/**
 * @author : zhy
 * @since : 2022/8/30
 * 柠檬水找零
 */
public class GiveChange {

    public boolean lemonadeChange(int[] bills) {
        int five=0;
        int ten=0;
        for(int bill:bills)
        {
            if(bill==5) {
                five++;
            }else if(bill==10) {
                ten++;
                five--;
            }else {
                if(ten>0){
                    ten--;
                    five--;
                }else {
                    five-=3;
                }
            }
            if(five<0||ten<0){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        int []can={5,5,10,10,20};
        GiveChange giveChange = new GiveChange();

        System.out.println(giveChange.lemonadeChange(can));
    }

}
